import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jspang/provide/cart.dart';
import 'package:provider/provider.dart';

class CartBottom extends StatelessWidget {
  const CartBottom({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(5.0),
      color: Colors.white,
      child: Selector<CartProvider, CartProvider>(
        selector: (context, provider) => provider,
        shouldRebuild: (pre, next) => true,
        builder: (context, value, child) {
          return Row(
            children: <Widget>[
              _selectAllbtn(context,value),
              _allPriceArea(context,value),
              _goButton(context,value)
            ],
          );
        },
      ),
    );
  }

  Widget _selectAllbtn(context,value) {
    return Container(
      child: Row(
        children: <Widget>[
          Checkbox(
            value: value.isAllCheck,
            activeColor: Colors.pink,
            onChanged: (bool val) {
              print(value.isAllCheck);
              print(val);
              Provider.of<CartProvider>(context,listen: false).changeAllCheckBtnState(val);
            },
          ),
          Text('全选')
        ],
      ),
    );
  }

  Widget _allPriceArea(context,value) {
    return Container(
      width: ScreenUtil().setWidth(380),
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                alignment: Alignment.centerRight,
                width: ScreenUtil().setWidth(190),
                child: Text(
                  '合计:',
                  style: TextStyle(fontSize: ScreenUtil().setSp(36)),
                ),
              ),
              Container(
                alignment: Alignment.center,
                width: ScreenUtil().setWidth(190),
                child: Text(
                  '￥${value.allPrice}',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(36), color: Colors.red),
                ),
              )
            ],
          ),
          Container(
            width: ScreenUtil().setWidth(430),
            alignment: Alignment.centerRight,
            child: Text(
              '满10元免配送费,预购免配送费',
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(22), color: Colors.black),
            ),
          )
        ],
      ),
    );
  }

  Widget _goButton(context,value) {
    return Container(
      width: ScreenUtil().setWidth(180),
      padding: EdgeInsets.only(left: 10),
      child: InkWell(
        onTap: () {},
        child: Container(
          padding: EdgeInsets.all(10.0),
          alignment: Alignment.center,
          decoration: BoxDecoration(
              color: Colors.red, borderRadius: BorderRadius.circular(3.0)),
          child: Text(
            '结算(${value.allGoodsCount})',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ),
    );
  }
}
